home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 483 / mkrscsrc / edit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-26  |  10.9 KB  |  426 lines

  1. #include "stdio.h"
  2. #include "gemdefs.h"
  3. #include "obdefs.h"
  4. #include "osbind.h"
  5. #include "mkrsc.h"
  6. #include "globals.h"
  7. #include "strings.h"
  8.  
  9.  
  10.  
  11. /*    find the selected obj[i]....    find the obj[j].ob_next
  12.     or ob_head pointing to it, point obj[j].ob_next or ob_head to
  13.     obj[i].ob_next....  check that obj[obj[i].ob_next].ob_tail is not
  14.     pointing back to the deleted object and if so point it to obj[j].
  15.     .....   check that neither obj[j].ob_head nor
  16.     obj[j].ob_tail point to themselves and if so set them to -1.
  17.     Cannot erase obj[0] or menuboxes in menu trees
  18.     When titles are erased, their menu boxes must be erased as well
  19. */
  20.  
  21. int erase_obj()
  22. {
  23.     OBJECT *inwinptr;
  24.     int        i, j, start, imbox;
  25.  
  26. /*    Set up handy pointer to right window object tree    */
  27.  
  28.         inwinptr = thefrontwin->inwindow->objt;
  29.         thefrontwin->saved = FALSE;
  30.  
  31.     if(thefrontwin->inwindow->kind[0] == TMENU)
  32.         start = 3;
  33.     else 
  34.         start = 1;
  35.  
  36.     for(i=start;i<(thefrontwin->inwindow->count + 1);i++)
  37.         if( (inwinptr[i].ob_state & SELECTED) &&
  38.              (i != thefrontwin->inwindow->mbox) )
  39.         {    
  40.             for(j=0;j<(thefrontwin->inwindow->count + 1);j++)
  41.             {    if(inwinptr[j].ob_head == i)
  42.                     {    inwinptr[j].ob_head = inwinptr[i].ob_next;
  43.                         break;
  44.                     }
  45.                 if(inwinptr[j].ob_next == i)
  46.                     {    inwinptr[j].ob_next = inwinptr[i].ob_next;
  47.                         break;
  48.                     }
  49.             }
  50.             if( inwinptr[inwinptr[i].ob_next].ob_tail == i)
  51.                 inwinptr[inwinptr[i].ob_next].ob_tail = j;
  52.  
  53. /*    if selected obj was a menu title, delete its menubox    */
  54.  
  55.             if(inwinptr[i].ob_type == G_TITLE)
  56.             {    imbox =    thefrontwin->inwindow->mbox;
  57.                     for(j=0;j<(thefrontwin->inwindow->count + 1);j++)
  58.                     {    if(inwinptr[j].ob_head == imbox)
  59.                             {inwinptr[j].ob_head = inwinptr[imbox].ob_next;
  60.                              break;
  61.                             }
  62.                         if(inwinptr[j].ob_next == imbox)
  63.                             {inwinptr[j].ob_next = inwinptr[imbox].ob_next;
  64.                              break;
  65.                             }
  66.                     }
  67.                     if( inwinptr[inwinptr[imbox].ob_next].ob_tail == imbox)
  68.                         inwinptr[inwinptr[imbox].ob_next].ob_tail = j;
  69.                 thefrontwin->inwindow->mbox = 0;
  70.             }
  71.             for(j=0;j<(thefrontwin->inwindow->count + 1);j++)
  72.             {    if(inwinptr[j].ob_head == j)
  73.                     inwinptr[j].ob_head = -1;
  74.                 if(inwinptr[j].ob_tail == j)
  75.                     inwinptr[j].ob_tail = -1;
  76.             }
  77.         break;  /* out of for i = ......    */
  78.         }
  79.     if(thefrontwin->inwindow->kind[0] == TMENU)
  80.         tidy_m();
  81.     else
  82.         ord_tree();
  83.  
  84.     draw_inwind(thefrontwin,0);
  85. }
  86.  
  87. int erase_tree()
  88. {
  89.     OBJECT    *inwinptr;
  90.     int    c, i, start;
  91.  
  92.     inwinptr = thefrontwin->inwindow->objt;
  93.  
  94.     start = 1;
  95.  
  96.     for(i=start;i<(thefrontwin->inwindow->count + 1);i++)
  97.         if(inwinptr[i].ob_state & SELECTED)
  98.         {    c = objc_delete(inwinptr,i);
  99.             free(thefrontwin->inwindow->treelink[i]);
  100.         }
  101. /*    ord_tree() will reorder tree and adjust count    */
  102.     ord_tree();
  103.     
  104.     for(i=start;i<(thefrontwin->inwindow->count + 1);i++)
  105.     {    inwinptr[i].ob_x = 20 + ((i-1)%8)*50;
  106.         inwinptr[i].ob_y = 20 + ((i-1)/8)*35;
  107.     }
  108.  
  109.     draw_inwind(thefrontwin,0);
  110.     thefrontwin->saved = FALSE;
  111. }
  112.  
  113. objtreeptr copy_tree(deselect)
  114.     int deselect;
  115. {
  116.     objtreeptr    tempmain, tempsub, inwinptr;
  117.     int i;
  118.  
  119.     tempmain  = (objtreeptr) malloc(sizeof(objtree));
  120.     tempsub  = (objtreeptr) malloc(sizeof(objtree));
  121.  
  122.     inwinptr = thefrontwin->inwindow;
  123.     thefrontwin->saved = FALSE;
  124.  
  125.     for(i=1;i<(inwinptr->count + 1);i++)
  126.     {    if(inwinptr->objt[i].ob_state & SELECTED)
  127.         {    if(deselect)
  128.                 inwinptr->objt[i].ob_state &= ~SELECTED;
  129.             tempmain->kind[0] = thefrontwin->inwindow->kind[i];
  130.             strcpy(tempmain->name[0],thefrontwin->inwindow->name[i]);
  131.             tempmain->icblk[0] = thefrontwin->inwindow->icblk[i];
  132.             tempmain->objt[0] = thefrontwin->inwindow->objt[i];
  133.             tempmain->objt[0].ob_state &= ~SELECTED;
  134.             tempmain->treelink[0] = tempsub;
  135.         
  136.             *tempsub = *inwinptr->treelink[i];
  137.             tempsub->kind[0] = tempmain->kind[0];
  138.             draw_inwind(thefrontwin,0);
  139.  
  140.             return(tempmain);
  141.         }
  142.     }
  143.             return(NULL);
  144.  
  145.  
  146. int    paste_tree(tempmain)
  147.     objtreeptr    tempmain;
  148. {
  149.     int result, num, nindex, i;
  150.     int cx,cy,cw,ch;
  151.     OBJECT *objptr2;
  152.     ICONBLK *ibptr;
  153.     objtreeptr    newsub, inwinptr;
  154.  
  155.     inwinptr = thefrontwin->inwindow;
  156.     thefrontwin->saved = FALSE;
  157.     
  158.     nindex = 0;
  159.     newsub  = (objtreeptr) malloc(sizeof(objtree));
  160.  
  161.     num = ++inwinptr->count;
  162.     inwinptr->kind[num] = tempmain->kind[0];
  163.     strcpy(inwinptr->name[num],tempmain->name[0]);
  164.     inwinptr->icblk[num] = tempmain->icblk[0];
  165.     inwinptr->objt[num] = tempmain->objt[0];
  166.     inwinptr->icblk[num].ib_ptext
  167.                          = inwinptr->name[num];
  168.     inwinptr->objt[num].ob_spec
  169.                         = (char *)&inwinptr->icblk[num];
  170.     *newsub = *tempmain->treelink[0];
  171.     inwinptr->treelink[num] = newsub;
  172.  
  173. /*    correct all of the pointers in the subtree    */
  174.  
  175.     for(i=0;i < newsub->count + 1;i++)
  176.     {    switch (newsub->objt[i].ob_type)
  177.         {
  178.             case G_TEXT        :
  179.             case G_BOXTEXT    :
  180.             case G_FTEXT    :
  181.             case G_FBOXTEXT    :
  182.                 newsub->objt[i].ob_spec = (char *)&newsub->ti[i];
  183.                 newsub->ti[i].te_ptext = newsub->strings[i];
  184.                 newsub->ti[i].te_ptmplt = newsub->template[i];
  185.                 newsub->ti[i].te_pvalid = newsub->valid[i];                
  186.                 break;
  187.             case G_BUTTON    :
  188.             case G_STRING    :
  189.             case G_TITLE    :
  190.                 newsub->objt[i].ob_spec = newsub->strings[i];
  191.                     break;
  192.             case G_ICON        :
  193.                 newsub->objt[i].ob_spec = (char *)&newsub->icblk[i];
  194.                 newsub->icblk[i].ib_ptext = newsub->strings[i];
  195.                     break;
  196.         }        
  197.     }
  198.  
  199.  
  200. /* set up a handy ptr */
  201.     objptr2 = &inwinptr->objt[num];
  202.  
  203. /* clear the pointers for the new object  */
  204.  
  205.     objptr2->ob_next = -1;
  206.     objptr2->ob_head = -1;
  207.     objptr2->ob_tail = -1;
  208.  
  209. /* set its position */
  210.  
  211.     objptr2->ob_x = 20 + ((num-1)%8)*50;
  212.     objptr2->ob_y = 20 + ((num-1)/8)*35;
  213.     
  214. /* make it a last object  */
  215.  
  216.     objptr2->ob_flags |= LASTOB;
  217.  
  218. /* get its new name, put into maintree name array */
  219.  
  220.     sprintf(inwinptr->name[num],"TREE%03d",++iconum);
  221.     
  222. /* point the tedinfo of the tree namer dialog to thetree->name */
  223.     {
  224.     ((TEDINFO *)newtree[NTEDIT].ob_spec)->te_ptext = 
  225.                                     inwinptr->name[num];
  226.     
  227.     result = do_dialog(newtree,NTEDIT);    /* newtree is object from RSC  */
  228.     newtree[NTOK].ob_state = NORMAL;
  229.     newtree[NTCANCEL].ob_state = NORMAL;
  230.  
  231.     if (result == NTCANCEL)
  232.         {    inwinptr->count--;
  233.             iconum--;
  234.             return;
  235.         }    
  236.     }
  237. /* link the new object into its parent   */
  238.  
  239.     result = objc_add(inwinptr->objt,nindex,num);
  240.     
  241. /* reset the LASTOB for the previous object in tree  */
  242.  
  243.     inwinptr->objt[num-1].ob_flags &= ~LASTOB;
  244.     
  245.     draw_inwind(thefrontwin,0);
  246. }
  247.         
  248. int copy_obj(deselect)
  249.     int deselect;
  250. {
  251.     objtree    *inwinptr;
  252.     int i;
  253.  
  254.     inwinptr = thefrontwin->inwindow;
  255.  
  256.     for(i=1;i<(inwinptr->count + 1);i++)
  257.         if(inwinptr->objt[i].ob_state & SELECTED)
  258.         {    if(deselect)
  259.                 inwinptr->objt[i].ob_state &= ~SELECTED;
  260.             tempo.okind = thefrontwin->inwindow->kind[i];
  261.             strcpy(tempo.oname,thefrontwin->inwindow->name[i]);
  262.             strcpy(tempo.ostrings,thefrontwin->inwindow->strings[i]);
  263.             strcpy(tempo.ovalid,thefrontwin->inwindow->valid[i]);
  264.             strcpy(tempo.otemplate,thefrontwin->inwindow->template[i]);
  265.             tempo.oti = thefrontwin->inwindow->ti[i];
  266.             tempo.oicblk = thefrontwin->inwindow->icblk[i];
  267.             tempo.oobjt = thefrontwin->inwindow->objt[i];
  268.             tempo.oobjt.ob_state &= ~SELECTED;
  269.             draw_inwind(thefrontwin,0);        
  270. /*            objc_draw(inwinptr->objt,i,10,thefrontwin->work.g_x,
  271.                         thefrontwin->work.g_y,
  272.                         thefrontwin->work.g_h,
  273.                         thefrontwin->work.g_w);
  274. */
  275.             spaste = TRUE;
  276.             return(1);
  277.         }
  278.         return(0);
  279. }
  280.  
  281. int paste_obj()
  282. {
  283.     int            nindex, x, y, sw, sh;
  284.     int result, num, obj_type, xoff, yoff, dummy, ev_bkstate;
  285.     int cx,cy,cw,ch;
  286.     OBJECT *objptr2;
  287.     objtreeptr thetree;
  288.     windowptr    thewin;
  289.  
  290.     graf_mouse(3,0);
  291.     evnt_button(1,1,1,&x,&y,&dummy,&ev_bkstate);
  292. /*    if the left-shift key is down wait for a button up and then
  293.     a second button dwn.
  294. */
  295.     if (ev_bkstate ==2)
  296.     {    evnt_button(1,1,0,&x,&y,&dummy,&ev_bkstate);
  297.         evnt_button(1,1,1,&x,&y,&dummy,&ev_bkstate);
  298.     }
  299.     graf_mouse(0,0);
  300.     
  301.     objptr2 = thefrontwin->inwindow->objt;
  302.  
  303. /*    objptr2 points to the active object tree in the window    */
  304.  
  305.     sw = tempo.oobjt.ob_width;
  306.     sh = tempo.oobjt.ob_height;
  307.     nindex = good_parent(objptr2,x,y,sw,sh,-2);
  308.     if(nindex == -1)
  309.         return;
  310.  
  311.     thewin = thefrontwin;
  312.     thetree = thefrontwin->inwindow;
  313.  
  314.     if (tempo.oobjt.ob_type == G_TITLE)
  315.     {
  316. /*    make sure you are moving a title to the menu bar    */
  317.         result = objc_find(thetree->objt,1,0,x,y);
  318.         if (result == 1)    
  319.         {    in_ttl(x,y,1);
  320.             draw_inwind(thefrontwin,0);
  321.         }
  322.         return;
  323.     }
  324.  
  325. /*    bail out if its a menu tree and the icon is not being dragged to a
  326.     menubox
  327. */
  328.  
  329.     if( (thetree->kind[0] == TMENU)
  330.         && (nindex != thetree->mbox
  331.             || tempo.oobjt.ob_type != G_STRING) )
  332.                 return;
  333.  
  334.     num = ++thetree->count;
  335.  
  336.     thetree->kind[num] = tempo.okind;
  337.     strcpy(thetree->name[num],tempo.oname);
  338.     strcpy(thetree->strings[num],tempo.ostrings);
  339.     strcpy(thetree->valid[num],tempo.ovalid);
  340.     strcpy(thetree->template[num],tempo.otemplate);
  341.     thetree->objt[num] = tempo.oobjt;
  342.  
  343. /* set up a handy ptr */
  344.     objptr2 = &thetree->objt[num];
  345.  
  346. /* clear the pointers for the new object  */
  347.  
  348.     objptr2->ob_next = -1;
  349.     objptr2->ob_head = -1;
  350.     objptr2->ob_tail = -1;
  351.  
  352. /* get the object type of object coming in    */
  353.  
  354.     obj_type = thetree->objt[num].ob_type;
  355.  
  356. /* set its position */
  357.  
  358.         objc_offset(thetree->objt, nindex, &xoff, &yoff); 
  359.         x -= xoff;
  360.         y -= yoff;
  361.         objptr2->ob_y = y;
  362.         objptr2->ob_x = x;
  363.         if(snap)
  364.         {    objptr2->ob_x += gl_wchar/2;
  365.             objptr2->ob_x &= 0xFFF8;
  366.             objptr2->ob_y += gl_hchar/2;
  367.             objptr2->ob_y &= (0xFFFF - gl_hchar + 1);
  368.         }
  369.  
  370. /* make if a last object  */
  371.  
  372.     objptr2->ob_flags |= LASTOB;
  373.  
  374. /* copy any necessary structures to the newtree structure  */
  375.  
  376.  
  377.     switch (obj_type)
  378.     {
  379.         case G_TEXT        :
  380.         case G_BOXTEXT    :
  381.         case G_FTEXT    :
  382.         case G_FBOXTEXT    : 
  383.             thetree->ti[num] = tempo.oti;
  384.             thetree->objt[num].ob_spec = (char *)&(thetree->ti[num]);
  385.             thetree->ti[num].te_ptext = thetree->strings[num];
  386.             thetree->ti[num].te_ptmplt = thetree->template[num];
  387.             thetree->ti[num].te_pvalid = thetree->valid[num];
  388.             break;
  389.         case G_BUTTON    :
  390.         case G_STRING    :
  391.         case G_TITLE    :
  392.             thetree->objt[num].ob_spec = thetree->strings[num];
  393.             break;
  394.         case G_ICON        :
  395.             thetree->icblk[num] = tempo.oicblk;
  396.             thetree->objt[num].ob_spec = (char *)&thetree->icblk[num];
  397.             thetree->icblk[num].ib_ptext = thetree->strings[num];
  398.             break;
  399.     }        
  400.  
  401.  
  402. /* link the new object into its parent   */
  403.  
  404.     if(thetree->kind[0] == TMENU)
  405.     {    thetree->objt[num].ob_width = min(thetree->objt[num].ob_width,
  406.                                 thetree->objt[thetree->mbox].ob_width);
  407.         thetree->objt[num].ob_x = 0;
  408.  
  409.         thetree->objt[num].ob_height = min(thetree->objt[num].ob_height,
  410.                                 thetree->objt[thetree->mbox].ob_height);
  411.         result = objc_add(thetree->objt,thetree->mbox,num);
  412.     }
  413.     else
  414.     {    thetree->objt[num].ob_width = min(thetree->objt[num].ob_width,
  415.                                 thetree->objt[0].ob_width);
  416.         thetree->objt[num].ob_height = min(thetree->objt[num].ob_height,
  417.                                 thetree->objt[0].ob_height);
  418.         result = objc_add(thetree->objt,nindex,thetree->count);
  419.     }
  420. /* reset the LASTOB for the previous object in tree  */
  421.  
  422.     thetree->objt[num-1].ob_flags &= ~LASTOB;
  423.  
  424. }
  425.